# Maintainer: Christian Rebischke <chris.rebischke@archlinux.org>

pkgname=popeye
pkgver=0.11.1
pkgrel=2
pkgdesc="Kubernetes cluster resource sanitizer"
arch=('loong64' 'x86_64')
url="https://github.com/derailed/popeye"
license=('Apache')
makedepends=('go' 'git')
depends=('glibc')
optdepends=('bash-completion')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/derailed/popeye/archive/v${pkgver}.tar.gz")
sha512sums=('575546e59d333f4b44b18b8baba203de15a2100eb031d828c8a9164f2ab6cb5ebc297050d7642cf28db8973974fe7c36f96d5ee55217c504b2f11f63b6884921')

build(){
  cd "${pkgname}-${pkgver}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw -ldflags=-linkmode=external"
  go build .
  chmod +x ./popeye
}

check(){
  cd "${pkgname}-${pkgver}"
  go test ./...
}

package(){
  cd "${pkgname}-${pkgver}"
  install -Dsm755 ./popeye "${pkgdir}/usr/bin/popeye"
  ./popeye completion bash | install --verbose -D --mode=0644 /dev/stdin "${pkgdir}/usr/share/bash-completion/completions/popeye"
  ./popeye completion fish | install --verbose -D --mode=0644 /dev/stdin  "${pkgdir}/usr/share/fish/vendor_completions.d/popeye.fish"
  ./popeye completion zsh | install --verbose -D --mode=0644 /dev/stdin  "${pkgdir}/usr/share/zsh/site-functions/_popeye"
}
